#encoding=utf8
'''
Created on 2012-10-17

@author: Administrator
'''
from Processor import Processor
from pub import Func, UserDict;
from pub.Config import Config

class UFSAClass(Processor):
    '''
    指令：UFSA(user friend second add)
    备注：用户验证好友请求
    格式：c-s:cmd #cmdID#userID#userIDTo#result#msg
     s-c:cmd #cmdID#userIDFrom#userIDTo#result#msg
    '''
    def __init__(self,):
        Processor.__init__(self);
        self.__userIdSend = 0;
        self.__userIdTo = 0;
        self.__result = Config.I_SYS_ZERO;
        self.__infos = "";         
        
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 4:      
            self.__userIdSend = Func.strToInt(cmdContent[0], Config.I_SYS_ZERO);
            self.__userIdTo = Func.strToInt(cmdContent[1], Config.I_SYS_ZERO);
            self.__result = Func.strToInt(cmdContent[2], Config.I_SYS_ZERO);            
            self.__infos = Func.toStr(cmdContent[3]);            
            return True;        
        return False;
    def outData(self,):
        userSend = UserDict.getUserFromUserDictById(self.__userIdSend);  
        if not userSend:
            return False;
        socket = userSend.get_socket();
        if not socket:
            return False;
        sendStr = self.setPackage([self.__userIdSend, self.__userIdTo, self.__result, self.__infos]);
        Func.sendMsg(socket, sendStr);
        return True;
        
             
